<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('维度管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
    <style>
        .layui-table-click {
            background-color:#1E9FFF;
            color:#fff;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>分类：</label>
                            <select id="sdCd" th:with="type=${@baseSd.getItem('sfxm_group')}" onchange="typeChange()">
                                <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                            </select>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12" style="margin-top: 10px;background-color: #fff;">
            <div class="col-sm-4"> <!--style="font-size:16px;margin-top:6px;"-->
                <table id="bootstrap-table" style="margin-top: 10px"></table>
            </div>
            <div class="col-sm-1"></div>
            <div class="col-sm-1" style="padding-top: 300px"> <!--style="font-size:16px;margin-top:6px;"-->
                <button type="button" class="btn btn-w-m btn-primary" onclick="getCds()">选中编码</button><br/><br/><br/>
                <button type="button" class="btn btn-w-m btn-info" onclick="toRight()">=></button><br/><br/><br/>
                <button type="button" class="btn btn-w-m btn-success" onclick="toLeft()"><=</button>
            </div>
            <div class="col-sm-1"></div>
            <div class="col-sm-5">
                <table id="main-table" style="margin-top: 10px"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: select2-js" />
<script type="text/javascript">
    var prefix = ctx + "md/med/dim";
    var tableName;
    function typeChange() {
        // var sdCd = $("#sdCd").val();
        $("#main-table").bootstrapTable('destroy');
        loadHosSfxmGroupTable();

    }
    function getCds() {
        debugger;
        $.ajax({
            type: "POST",
            url: "/hos/sfxm/list",
            data: JSON.stringify({"sdCd":$("#sdCd").val()}),
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            success: function(res) {
                if(res.code==0) {
                    var rows = res.rows;
                    if(rows.length==0) {
                        $.modal.alertError("暂未分配项目");
                    }
                    var cds="";
                    $.each(rows,function (index,item) {
                        cds += "'"+item.cdSfxm+"',";
                    });
                    $.modal.alertSuccess(cds.substring(0,cds.length-1));
                } else {
                    $.modal.alertError(res.msg);
                }
            }
        });
    }
    function loadHosSfxmGroupTable() {
        $('#main-table').bootstrapTable({
            url: "/hos/sfxm/list",
            method: "post",
            contentType: "application/json",
            modalName: "执行数据",
            showSearch: false,
            showRefresh: true,
            showToggle: false,
            showColumns: false,
            queryParams: function (params) {
                return {
                    "sdCd":$("#sdCd").val()
                };
            },
            columns: [{
                checkbox: true
            },{
                field: 'idSfxmGroup',
                title: '主键',
                visible: false
            },
                {
                    field: 'sdNa',
                    title: '分类名称'
                },
                {
                    field: 'cdSfxm',
                    title: '项目编码'
                },
                {
                    field: 'naSfxm',
                    title: '项目名称'
                },
                {
                    field: 'naEmpCre',
                    title: '添加人'
                }]
        });
    }
    function toRight() {
        var rows = $("#bootstrap-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var param=[];
        var sdCd = $("#sdCd").val();
        debugger;
        var naCd = $("#sdCd").find("option:selected").text();
        $.each(rows,function (index,item) {
            param.push({"cdSfxm":item.cd,"naSfxm":item.na,"sdCd":sdCd,"sdNa":naCd});
        });
        $.ajax({
            type: "POST",
            url: "/hos/sfxm/saveBatch",
            data: JSON.stringify(param),
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            success: function(res) {
                if(res.code==0) {
                    $("#main-table").bootstrapTable('refreshOptions',{pageNumber:1});  // pageNumber:1, 指定页码为第1页
                    $("#main-table").bootstrapTable('refresh');
                } else {
                    $.modal.alertError(res.msg);
                }
            }
        });
    }

    function toLeft() {
        var rows = $("#main-table").bootstrapTable('getSelections');
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var ids="";
        $.each(rows,function (index,item) {
            ids += item.idSfxmGroup+","
        });
        $.ajax({
            type: "POST",
            url: "/hos/sfxm/remove?ids="+ids,
            dataType: 'json',
            success: function(res) {
                if(res.code==0) {
                    $("#main-table").bootstrapTable('refreshOptions',{pageNumber:1});  // pageNumber:1, 指定页码为第1页
                    $("#main-table").bootstrapTable('refresh');
                } else {
                    $.modal.alertError(res.msg);
                }
            }
        });
    }
    function loadDimTable() {
        $('#bootstrap-table').bootstrapTable({
            url: "/md/med/dim/findDimDataByPage/?tableName=MD_DIM_CGITEM",
            method:"get",
            modalName: "执行数据",
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            pageSize:15,
            search: true,
            sidePagination: 'client',
            showRefresh : true,
            columns: [{
                checkbox: true
            },{
                field: 'idPubfld',
                title: '主键',
                visible: false
            },
                {
                    field: 'cd',
                    title: '编码'
                },
                {
                    field: 'na',
                    title: '名称'
                }]
        });
    }

    $(function(){
        loadDimTable();
        loadHosSfxmGroupTable();
    });
</script>
</body>
</html>